//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

namespace Mindscape.BackgroundMotion.Core.Validators
{
  /// <summary>
  /// The base class for all validator attributes which are custom to the Background Motion system
  /// </summary>
  public abstract class CustomValidatorAttribute : ValidatorAttribute
  {
    private readonly string _fieldName;

    public CustomValidatorAttribute(string fieldName)
    {
      _fieldName = fieldName;
    }

    /// <summary>
    /// The name of the field which the validator is associated with
    /// </summary>
    public string FieldName
    {
      get { return _fieldName; }
    }
  }

  /// <summary>
  /// The base class for all validators which are custom to the Background Motion system
  /// </summary>
  public abstract class CustomValidator<T> : Validator<T>
  {
    protected readonly string _fieldName;

    public CustomValidator(string fieldName)
      : base(null, null)
    {
      _fieldName = fieldName;
    }

    protected abstract string MessageResource { get; }

    protected override string DefaultMessageTemplate
    {
      get { return string.Format(MessageResource, _fieldName); }
    }
  }
}